package version1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class updateWeight {
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		BufferedReader stdin = new BufferedReader(new InputStreamReader(
				System.in));
		
		File file = new File(args[0]);
		FileInputStream f = new FileInputStream(file);
		ObjectInputStream sS = new ObjectInputStream(f);
		HashMap<Integer,String> np = new HashMap<Integer,String>();
		np = (HashMap<Integer, String>) sS.readObject();
		FileReader f1 = new FileReader(args[1]);
		BufferedReader bufin = new BufferedReader(f1);
		String msg = null;
		int times = 1000;

		int[] text = new int[99400];
		while ((msg = stdin.readLine()) != null) {
			String[] s = msg.split("\\t");
			int nPhrase = Integer.valueOf(s[0]).intValue();
			int count = Integer.valueOf(s[1]).intValue();
			String numOfContext = np.get(nPhrase);
			String[] context = numOfContext.split("^");
			for(int i = 0;i<context.length;i++){
				int num = Integer.valueOf(context[i]).intValue();
				text[num] += count;
			}
		}
		for(int j = 0;j<text.length;j++){
			double prob = (text[j]*1.0)/(times*1.0);
			System.out.println(j+"$"+prob);
		}
	}

}

//ArrayList<ArrayList<Integer>> np = new ArrayList<ArrayList<Integer>>();
//while((msg = bufin.readLine())!=null){
//	String[] s = msg.split("\\t");
//	String[] context = s[1].split("+");
//	ArrayList<Integer> text = new ArrayList<Integer>();
//	for(int i =0 ;i < context.length;i++){
//		int tmp = Integer.valueOf(context[i]).intValue();
//		text.add(tmp);		
//	}
//	np.add(text);
//}
